import {
    CacheOptionsFactory,
    Injectable,
    CacheModuleOptions
} from '@nestjs/common'
import { ConfigService } from './config.service'
import * as redisStore from 'cache-manager-redis-store'
@Injectable()
export class CacheConfigService implements CacheOptionsFactory {
    // 注入config service取得env变量
    constructor(private readonly configService: ConfigService) {} // 就是回传TypeOrmOptions对象
    createCacheOptions(): CacheModuleOptions {
        return {
            store: redisStore,
            host: this.configService.get('REDIS_HOST'),
            port: this.configService.getNumber('REDIS_PORT'),
            ttl: 5
        }
    }
}
